<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="业主ID" prop="owCode">
      <el-input v-model="dataForm.owCode" placeholder="业主ID"></el-input>
    </el-form-item>
    <el-form-item label="业主名称" prop="owDesc">
      <el-input v-model="dataForm.owDesc" placeholder="业主名称"></el-input>
    </el-form-item>
    <el-form-item label="业主分类" prop="owClass">
      <el-input v-model="dataForm.owClass" placeholder="业主分类"></el-input>
    </el-form-item>
    <el-form-item label="所属国家" prop="owCountry">
      <el-input v-model="dataForm.owCountry" placeholder="所属国家"></el-input>
    </el-form-item>
    <el-form-item label="省" prop="owProvince">
      <el-input v-model="dataForm.owProvince" placeholder="省"></el-input>
    </el-form-item>
    <el-form-item label="市" prop="owCity">
      <el-input v-model="dataForm.owCity" placeholder="市"></el-input>
    </el-form-item>
    <el-form-item label="详细地址" prop="owAddress">
      <el-input v-model="dataForm.owAddress" placeholder="详细地址"></el-input>
    </el-form-item>
    <el-form-item label="联系电话" prop="owPhone">
      <el-input v-model="dataForm.owPhone" placeholder="联系电话"></el-input>
    </el-form-item>
    <el-form-item label="主要联系人" prop="owPerson">
      <el-input v-model="dataForm.owPerson" placeholder="主要联系人"></el-input>
    </el-form-item>
    <el-form-item label="邮件地址" prop="owEmail">
      <el-input v-model="dataForm.owEmail" placeholder="邮件地址"></el-input>
    </el-form-item>
    <el-form-item label="所属发电企业" prop="owEnterprise">
      <el-input v-model="dataForm.owEnterprise" placeholder="所属发电企业"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          owId: 0,
          owCode: '',
          owDesc: '',
          owClass: '',
          owCountry: '',
          owProvince: '',
          owCity: '',
          owAddress: '',
          owPhone: '',
          owPerson: '',
          owEmail: '',
          owEnterprise: '',
          owCreated: '',
          owUpdate: '',
          owUdfchar01: '',
          owUdfchar02: '',
          owUdfchar03: '',
          owUdfchar04: '',
          owUdfchar05: '',
          owUdfchar06: '',
          owUdfchar07: '',
          owUdfchar08: '',
          owUdfchar09: '',
          owUdfchar10: '',
          owUdfnumber01: '',
          owUdfnumber02: '',
          owUdfnumber03: '',
          owUdfnumber04: '',
          owUdfnumber05: '',
          owUdfnumber06: '',
          owUdfnumber07: '',
          owUdfnumber08: '',
          owUdfnumber09: '',
          owUdfnumber10: ''
        },
        dataRule: {
          owCode: [
            { required: true, message: '业主ID不能为空', trigger: 'blur' }
          ],
          owDesc: [
            { required: true, message: '业主名称不能为空', trigger: 'blur' }
          ]
          // owClass: [
          //   { required: true, message: '业主分类不能为空', trigger: 'blur' }
          // ],
          // owCountry: [
          //   { required: true, message: '所属国家不能为空', trigger: 'blur' }
          // ],
          // owProvince: [
          //   { required: true, message: '省不能为空', trigger: 'blur' }
          // ],
          // owCity: [
          //   { required: true, message: '市不能为空', trigger: 'blur' }
          // ],
          // owAddress: [
          //   { required: true, message: '详细地址不能为空', trigger: 'blur' }
          // ],
          // owPhone: [
          //   { required: true, message: '联系电话不能为空', trigger: 'blur' }
          // ],
          // owPerson: [
          //   { required: true, message: '主要联系人不能为空', trigger: 'blur' }
          // ],
          // owEmail: [
          //   { required: true, message: '邮件地址不能为空', trigger: 'blur' }
          // ],
          // owEnterprise: [
          //   { required: true, message: '所属发电企业不能为空', trigger: 'blur' }
          // ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.owId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.owId) {
            this.$http({
              url: this.$http.adornUrl(`/udp/r5rmowner/info/${this.dataForm.owId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.owCode = data.r5rmOwner.owCode
                this.dataForm.owDesc = data.r5rmOwner.owDesc
                this.dataForm.owClass = data.r5rmOwner.owClass
                this.dataForm.owCountry = data.r5rmOwner.owCountry
                this.dataForm.owProvince = data.r5rmOwner.owProvince
                this.dataForm.owCity = data.r5rmOwner.owCity
                this.dataForm.owAddress = data.r5rmOwner.owAddress
                this.dataForm.owPhone = data.r5rmOwner.owPhone
                this.dataForm.owPerson = data.r5rmOwner.owPerson
                this.dataForm.owEmail = data.r5rmOwner.owEmail
                this.dataForm.owEnterprise = data.r5rmOwner.owEnterprise
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/udp/r5rmowner/${!this.dataForm.owId ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'owId': this.dataForm.owId || undefined,
                'owCode': this.dataForm.owCode,
                'owDesc': this.dataForm.owDesc,
                'owClass': this.dataForm.owClass,
                'owCountry': this.dataForm.owCountry,
                'owProvince': this.dataForm.owProvince,
                'owCity': this.dataForm.owCity,
                'owAddress': this.dataForm.owAddress,
                'owPhone': this.dataForm.owPhone,
                'owPerson': this.dataForm.owPerson,
                'owEmail': this.dataForm.owEmail,
                'owEnterprise': this.dataForm.owEnterprise
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
